import Vue from 'vue'

import Cookies from 'js-cookie'
import './utils/directives.js'

// 全局变量和方法
import MyGlobal from "@/api/MyGlobal.js";
import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/xintai.scss' // xintai css
import App from './App'
import store from './store'
import router from './router'
import permission from './directive/permission'


import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { getUserProfile } from "@/api/system/user";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/xintai";
import Pagination from "@/components/Pagination";
// 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar";
// 自定义弹出层
import MyDialog from "@/components/MyDialog/MyDialog";
// 仓库
import MyCangku from "@/components/cangkukuwei/cangku";
// 库位
import MyKuwei from "@/components/cangkukuwei/kuwei";
//全局生产线选择
import MyWorkshop from "@/components/workshop/index";
// 选择用户
import MySelectUser from "@/components/erp/selectUser/selectUser";
// 字典数据选择
import MyDictdata from "@/components/DictData/dictData";
// 经办人选择
import MyJbr from "@/components/erp/client/jingbanren";
// 材质
import MyCaizhi from "@/components/erp/sytem/ErpCaizhi";
// 轧硬派车司机
import MyOtherSiJi from "@/components/erp/OtherSiJi/OtherSiJi";
// 内容页中显示或隐藏，刷新按钮组件， 此组件移除显示隐藏搜索按钮
import MyRightToolbar from "@/components/MyRightToolbar";
// 客户选择
import MyClientSelect from "@/components/erp/client/clientSelect";
// 文件上传组件
import MyFileUpload from "@/components/FileUpload";
// 基建二级项目
import MyJiJian from "@/components/erp/jijian";

// 代码高亮插件
import hljs from 'highlight.js'
import 'highlight.js/styles/github-gist.css'

//审核流程
import addNode from '@/components/Approval/addNode'
import nodeWrap from '@/components/Approval/nodeWrap'
//审核验证
import func from '@/utils/preload'
Vue.prototype.$func = func;

// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getUserProfile = getUserProfile
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.Global = MyGlobal

Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: "success" });
}

Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: "error" });
}

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
}

// 全局组件挂载
Vue.component('Pagination', Pagination);
Vue.component('RightToolbar', RightToolbar);
// 生产线选择
Vue.component('MyWorkshop', MyWorkshop);
// 弹出层
Vue.component('MyDialog', MyDialog);
// 仓库
Vue.component('MyCangku', MyCangku);
// 库位
Vue.component('MyKuwei', MyKuwei);
// 用户选择
Vue.component('MySelectUser', MySelectUser);
// 经办人选择
Vue.component('MyJbr', MyJbr);
// 数据字典选择
Vue.component('MyDictdata', MyDictdata);
// 选择材质
Vue.component('MyCaizhi', MyCaizhi)
//审批组件
Vue.component("addNode",addNode)
Vue.component("nodeWrap",nodeWrap)
// 轧硬派单司机选择
Vue.component('MyOtherSiJi', MyOtherSiJi);
// 内容页中显示或隐藏，刷新按钮组件， 此组件移除显示隐藏搜索按钮
Vue.component('MyRightToolbar', MyRightToolbar);
// 客户选择
Vue.component('MyClientSelect', MyClientSelect);
// 文件上传组件
Vue.component('MyFileUpload', MyFileUpload);
// 基建二级项目
Vue.component('MyJiJian', MyJiJian);

Vue.use(permission);
Vue.use(hljs.vuePlugin);

//审核验证
Vue.directive('enterNumber', {
  bind: function(el, { value = 2 }) {
    el = el.nodeName == "INPUT" ? el : el.children[0]
    var RegStr = value == 0 ? `^[\\+\\-]?\\d+\\d{0,0}` : `^[\\+\\-]?\\d+\\.?\\d{0,${value}}`;
    el.addEventListener('keyup', function() {
      el.value = el.value.match(new RegExp(RegStr, 'g'));
      el.dispatchEvent(new Event('input'))
    })
  }
});

Vue.directive('focus', {
  // 当被绑定的元素插入到 DOM 中时……
  inserted: function(el) {
    el.focus()
  }
});
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
